﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Default.Master" AutoEventWireup="true"
  CodeBehind="Products.aspx.cs" Inherits="SaleManagement.Web.Pages.Products" %>

<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dxpc" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <table width="100%" class="">
    <tr>
      <td class="search_header">
        Danh mục hàng hóa
      </td>
    </tr>
    <tr>
      <td>
        <table style="width: 100%;">
          <tr>
            <td style="height: 19px">
              <asp:Literal ID="Literal5" runat="server" Text="Mã sản phẩm"></asp:Literal>
              :
            </td>
            <td style="height: 19px">
              <dxe:ASPxTextBox ID="txtSearchCode" runat="server" Width="130px" ClientInstanceName="txtSearchCode"
                CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
                <ValidationSettings>
                  <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                  <ErrorFrameStyle ImageSpacing="4px">
                    <ErrorTextPaddings PaddingLeft="4px" />
                  </ErrorFrameStyle>
                </ValidationSettings>
              </dxe:ASPxTextBox>
            </td>
            <td style="height: 19px">
            </td>
            <td style="height: 19px">
              <asp:Literal ID="Literal6" runat="server" Text="Tên sản phẩm"></asp:Literal>
              :
            </td>
            <td style="height: 19px">
              <div style="float: left;">
              </div>
              <dxe:ASPxTextBox ID="txtSearchName" runat="server" Width="130px" ClientInstanceName="txtSearchName"
                CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
                <ValidationSettings>
                  <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                  <ErrorFrameStyle ImageSpacing="4px">
                    <ErrorTextPaddings PaddingLeft="4px" />
                  </ErrorFrameStyle>
                </ValidationSettings>
              </dxe:ASPxTextBox>
            </td>
            <td style="height: 19px">
              <asp:Literal ID="Literal1" runat="server" Text="Nhóm"></asp:Literal>
              :
            </td>
            <td style="height: 19px">
              <dxe:ASPxComboBox ID="cbxSearchGroup" ClientInstanceName="cbxSearchGroup" TextField="Name"
                ValueField="Id" ValueType="System.Int32" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                CssPostfix="Aqua" Width="130px" ImageFolder="~/App_Themes/Aqua/{0}/" LoadingPanelText=""
                ShowShadow="False">
                <ButtonEditEllipsisImage Height="3px" Url="~/App_Themes/Aqua/Editors/edtEllipsis.png"
                  UrlDisabled="~/App_Themes/Aqua/Editors/edtEllipsisDisabled.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtEllipsisHottracked.png"
                  UrlPressed="~/App_Themes/Aqua/Editors/edtEllipsisPressed.png" />
                <DropDownButton>
                  <Image Height="7px" Url="~/App_Themes/Aqua/Editors/edtDropDown.png" UrlDisabled="~/App_Themes/Aqua/Editors/edtDropDownDisabled.png"
                    UrlHottracked="~/App_Themes/Aqua/Editors/edtDropDownHottracked.png" UrlPressed="~/App_Themes/Aqua/Editors/edtDropDownPressed.png" />
                </DropDownButton>
                <ValidationSettings>
                  <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                  <ErrorFrameStyle ImageSpacing="4px">
                    <ErrorTextPaddings PaddingLeft="4px" />
                  </ErrorFrameStyle>
                </ValidationSettings>
              </dxe:ASPxComboBox>
            </td>
            <td style="padding-left: 10px;">
              <dxe:ASPxButton ID="ASPxButton1" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                CssPostfix="Aqua" Text="Tìm kiếm" ClientInstanceName="btnSearch">
                <Image Url="../Images/find.png" />
                <ClientSideEvents Click="function(s,e){onbtnSearch(s,e);e.processOnServer=false;}" />
              </dxe:ASPxButton>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
  <div>
    <dxwgv:ASPxGridView ID="gvProduct" runat="server" Width="100%" AutoGenerateColumns="False"
      CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" KeyFieldName="CustomerID"
      OnCustomCallback="gvProduct_CustomCallback" OnCustomJSProperties="gvProduct_CustomJSProperties"
      OnPageIndexChanged="gvProduct_PageIndexChanged" ClientInstanceName="gvProduct"
      OnHtmlDataCellPrepared="gvProduct_HtmlDataCellPrepared">
      <SettingsBehavior AllowDragDrop="false" AllowSort="false" AllowGroup="False" />
      <Styles CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
      </Styles>
      <Columns>
        <dxwgv:GridViewDataTextColumn Name="Command" VisibleIndex="0" Width="8%">
          <DataItemTemplate>
            <img src="../Images/delete.png" onclick="onDelete('<%#Eval("Id") %>')" style="cursor: pointer"
              alt="" />
            <img src="../Images/edit.png" runat="server" id="imgEdit" style="cursor: pointer;"
              alt="" />
          </DataItemTemplate>
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn Width="15%" FieldName="Code" VisibleIndex="1" Caption="Ký hiệu hàng hóa">
          <HeaderStyle HorizontalAlign="Center" />
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn Width="15%" FieldName="Name" VisibleIndex="1" Caption="Tên hàng hóa">
          <HeaderStyle HorizontalAlign="Center" />
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn FieldName="MinQuantity" Caption="SL cảnh báo"
          VisibleIndex="3">
          <HeaderStyle HorizontalAlign="Center" />
          <CellStyle HorizontalAlign="Right">
          </CellStyle>
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn FieldName="GuaranteePeriod" Caption="Hạn bảo hành"
          VisibleIndex="3">
          <HeaderStyle HorizontalAlign="Center" />
          <CellStyle HorizontalAlign="Right">
          </CellStyle>
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataMemoColumn Width="20%" FieldName="Description" VisibleIndex="4"
          Caption="Mô tả">
          <HeaderStyle HorizontalAlign="Center" />
        </dxwgv:GridViewDataMemoColumn>
        <dxwgv:GridViewDataMemoColumn FieldName="GroupId" Visible="false">
          <HeaderStyle HorizontalAlign="Center" />
        </dxwgv:GridViewDataMemoColumn>
      </Columns>
      <Images ImageFolder="~/App_Themes/Aqua/{0}/">
        <CollapsedButton Height="15px" Width="13px" Url="~/App_Themes/Aqua/GridView/gvCollapsedButton.png" />
        <ExpandedButton Height="15px" Width="13px" Url="~/App_Themes/Aqua/GridView/gvExpandedButton.png" />
        <DetailCollapsedButton Height="15px" Width="13px" Url="~/App_Themes/Aqua/GridView/gvDetailCollapsedButton.png" />
        <DetailExpandedButton Height="15px" Width="13px" Url="~/App_Themes/Aqua/GridView/gvDetailExpandedButton.png" />
        <HeaderFilter Height="19px" Url="~/App_Themes/Aqua/GridView/gvHeaderFilter.png" Width="19px" />
        <HeaderActiveFilter Height="19px" Url="~/App_Themes/Aqua/GridView/gvHeaderFilterActive.png"
          Width="19px" />
        <HeaderSortDown Height="5px" Width="6px" Url="~/App_Themes/Aqua/GridView/gvHeaderSortDown.png" />
        <HeaderSortUp Height="5px" Width="6px" Url="~/App_Themes/Aqua/GridView/gvHeaderSortUp.png" />
        <FilterRowButton Height="13px" Width="13px" />
        <CustomizationWindowClose Width="18px" />
        <PopupEditFormWindowClose Width="18px" />
        <WindowResizer Height="13px" Width="12px" Url="~/App_Themes/Aqua/GridView/WindowResizer.png" />
        <FilterBuilderClose Width="18px" />
      </Images>
      <ClientSideEvents EndCallback="function(s, e) {
	ongvProduct_EndCallback(s,e);
}" />
      <StylesEditors>
        <ProgressBar Height="25px">
        </ProgressBar>
      </StylesEditors>
      <ImagesEditors>
        <CalendarPrevYear Width="23px" />
        <CalendarPrevMonth Width="19px" />
        <CalendarNextMonth Width="19px" />
        <CalendarNextYear Width="23px" />
        <CalendarFastNavPrevYear Height="19px" Url="~/App_Themes/Aqua/Editors/edtCalendarFNPrevYear.png" />
        <CalendarFastNavNextYear Height="19px" Url="~/App_Themes/Aqua/Editors/edtCalendarFNNextYear.png" />
        <DropDownEditDropDown Height="7px" Url="~/App_Themes/Aqua/Editors/edtDropDown.png"
          UrlDisabled="~/App_Themes/Aqua/Editors/edtDropDownDisabled.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtDropDownHottracked.png" />
        <SpinEditIncrement Height="6px" Url="~/App_Themes/Aqua/Editors/edtSpinEditIncrementImage.png"
          UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditIncrementDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditIncrementHottrackedImage.png"
          UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditIncrementHottrackedImage.png" />
        <SpinEditDecrement Height="7px" Url="~/App_Themes/Aqua/Editors/edtSpinEditDecrementImage.png"
          UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditDecrementDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditDecrementHottrackedImage.png"
          UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditDecrementHottrackedImage.png" />
        <SpinEditLargeIncrement Height="9px" Url="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncImage.png"
          UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncHottrackedImage.png"
          UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncHottrackedImage.png" />
        <SpinEditLargeDecrement Height="9px" Url="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecImage.png"
          UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecHottrackedImage.png"
          UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecHottrackedImage.png" />
      </ImagesEditors>
      <SettingsLoadingPanel Text="" />
      <SettingsPager>
        <AllButton>
          <Image Height="19px" Width="28px" />
        </AllButton>
        <FirstPageButton>
          <Image Height="19px" Width="23px" />
        </FirstPageButton>
        <LastPageButton>
          <Image Height="19px" Width="23px" />
        </LastPageButton>
        <NextPageButton>
          <Image Height="19px" Width="19px" />
        </NextPageButton>
        <PrevPageButton>
          <Image Height="19px" Width="19px" />
        </PrevPageButton>
      </SettingsPager>
    </dxwgv:ASPxGridView>
  </div>
  <div style="padding-top: 5px;">
    <dxe:ASPxButton ID="btnAdd" runat="server" Text="Thêm mới" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
      CssPostfix="Aqua" AutoPostBack="False">
      <Image Url="../Images/add.png" />
      <ClientSideEvents Click="function(s, e) {
	onAdd();e.processOnServer = false;
}" />
    </dxe:ASPxButton>
  </div>
  <div>
    <dxpc:ASPxPopupControl ID="pcEditProduct" ClientInstanceName="pcEditProduct" runat="server"
      CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" ImageFolder="~/App_Themes/Aqua/{0}/"
      Width="461px" PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter"
      HeaderText="Thông tin sản phẩm" CloseAction="CloseButton" Modal="True">
      <ContentStyle VerticalAlign="Top">
      </ContentStyle>
      <SizeGripImage Height="12px" Width="12px" />
      <ContentCollection>
        <dxpc:PopupControlContentControl>
          <div>
            <dxe:ASPxLabel ID="lblErrorMessage" ClientInstanceName="lblErrorMessage" runat="server"
              Font-Bold="True" ForeColor="#FF3300">
            </dxe:ASPxLabel>
          </div>
          <table>
            <tr>
              <td style="width: 150px;">
                <asp:Label ID="Label6" runat="server" Text="Ký hiệu hàng hóa"></asp:Label>
                :
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtCode" ClientInstanceName="txtCode" runat="server" Width="170px"
                  CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
            </tr>
            <tr>
              <td>
                <asp:Label ID="Label1" runat="server" Text="Tên hàng hóa"></asp:Label>
                :
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtName" ClientInstanceName="txtName" runat="server" Width="170px"
                  CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
            </tr>
            <tr>
              <td style="padding-top: 4px;" valign="top">
                <asp:Label ID="Label2" runat="server" Text="Nhóm hàng hóa"></asp:Label>
                :
              </td>
              <td>
                <dxe:ASPxComboBox ID="cbxGroup" ClientInstanceName="cbxGroup" TextField="Name" ValueField="Id"
                  ValueType="System.Int32" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua" Width="170px" ImageFolder="~/App_Themes/Aqua/{0}/" LoadingPanelText=""
                  ShowShadow="False">
                  <ButtonEditEllipsisImage Height="3px" Url="~/App_Themes/Aqua/Editors/edtEllipsis.png"
                    UrlDisabled="~/App_Themes/Aqua/Editors/edtEllipsisDisabled.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtEllipsisHottracked.png"
                    UrlPressed="~/App_Themes/Aqua/Editors/edtEllipsisPressed.png" />
                  <DropDownButton>
                    <Image Height="7px" Url="~/App_Themes/Aqua/Editors/edtDropDown.png" UrlDisabled="~/App_Themes/Aqua/Editors/edtDropDownDisabled.png"
                      UrlHottracked="~/App_Themes/Aqua/Editors/edtDropDownHottracked.png" UrlPressed="~/App_Themes/Aqua/Editors/edtDropDownPressed.png" />
                  </DropDownButton>
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxComboBox>
              </td>
            </tr>
            <tr>
              <td>
                <asp:Label ID="Label3" runat="server" Text="Số lượng cảnh báo"></asp:Label>
                :
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtMinQuantity" ClientInstanceName="txtMinQuantity" runat="server"
                  Width="170px" CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
            </tr>
            <tr>
              <td>
                <asp:Label ID="Label4" runat="server" Text="Thời hạn bảo hành"></asp:Label>
                :
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtGuaranteePeriod" ClientInstanceName="txtGuaranteePeriod" runat="server"
                  Width="170px" CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                     <MaskSettings IncludeLiterals="None" Mask="&lt;0..9999999999999999999g&gt;" />
                </dxe:ASPxTextBox>
              </td>
            </tr>
            <tr>
              <td>
                <asp:Label ID="Label5" runat="server" Text="Mô tả"></asp:Label>
                :
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtDescription" runat="server" ClientInstanceName="txtDescription"
                  CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" Width="300px">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
            </tr>
            <tr>
              <td>
              </td>
              <td style="padding-top: 4px;">
                <div style="float: left;">
                  <dxe:ASPxButton ID="btnSave" runat="server" AutoPostBack="False" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                    CssPostfix="Aqua" Text="Lưu">
                    <Image Url="../Images/save.png" />
                    <ClientSideEvents Click="function(s, e) {
	                          onSave();
                        }" />
                  </dxe:ASPxButton>
                </div>
                <div style="float: left; padding-left: 3px;">
                  <dxe:ASPxButton ID="btnCancel" runat="server" AutoPostBack="False" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                    CssPostfix="Aqua" Text="Đóng">
                    <Image Url="../Images/cancel.png" />
                    <ClientSideEvents Click="function(s, e) {
	                            onCancel(); e.processOnServer = false;
                      }" />
                  </dxe:ASPxButton>
                </div>
              </td>
            </tr>
          </table>
        </dxpc:PopupControlContentControl>
      </ContentCollection>
      <CloseButtonImage Height="16px" Width="18px" />
      <HeaderStyle Font-Bold="True" ForeColor="#59A1EF" />
    </dxpc:ASPxPopupControl>
  </div>
  <div>
    <asp:HiddenField ID="hfProductId" runat="server" />
  </div>

  <script type="text/javascript" language="javascript">
    function onAdd() {
      resetValue();
      pcEditProduct.Show();
    }

    function onEdit(index) {
      lblErrorMessage.SetText('');
      gvProduct.GetRowValues(index, 'Id;GroupId;Code;Name;Description;MinQuantity;GuaranteePeriod', fillRowValue);
    }

    function onDelete(id) {
      if (confirm('Bạn có chắc là muốn xóa sản phẩm này?'))
        gvProduct.PerformCallback('Delete|' + id);
    }

    function onSave() {
      if (checkInput())
        gvProduct.PerformCallback('Save|');
    }

    function onbtnSearch(s, e) {
      gvProduct.PerformCallback('Search|');
    }

    function onCancel() {
      pcEditProduct.Hide();
    }

    function resetValue() {
      lblErrorMessage.SetText('');
      document.getElementById('<%=hfProductId.ClientID %>').value = '';
      cbxGroup.SetValue('');
      txtCode.SetText('');
      txtName.SetText('');
      txtDescription.SetText('');
      txtMinQuantity.SetText('');
      txtGuaranteePeriod.SetText('');
    }

    function checkInput() {
      var error = '';
      var code = txtCode.GetText();
      if (txtName.GetText() == '') {
        error += '<BR> + ' + 'Tên hàng hóa không được bỏ trống';
      }
      if (cbxGroup.GetValue() == '') {
        error += '<BR> + ' + 'Nhóm hàng hóa không được bỏ trống'
      }
      if (error != '') {
        lblErrorMessage.SetText(error);
        return false;
      }
      return true;
    }

    function fillRowValue(values) {
      //Id;GroupId;Code;Name;Description;Price;MinQuantit
      document.getElementById('<%=hfProductId.ClientID %>').value = values[0];
      cbxGroup.SetValue(values[1]);
      txtCode.SetText(values[2]);
      txtName.SetText(values[3]);
      txtDescription.SetText(values[4]);
      txtMinQuantity.SetText(values[5]);
      txtGuaranteePeriod.SetText(values[6]);
      pcEditProduct.Show();
    }

    function ongvProduct_EndCallback(s, e) {
      var error = gvProduct.cpInnerError.split('|');
      if (error[0] == 'Save') {
        if (error[1] != '')
          lblErrorMessage.SetText(error[1]);
        else {
          pcEditProduct.Hide();
          alert('Cập nhật thành công');
        }
      }
      else if (error[0] != '') {
        alert(error[0]);
      }

    }
  </script>

</asp:Content>
